package com.guoheng.hazard.sys.service.impl.entpr;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guoheng.hazard.common.base.Result;
import com.guoheng.hazard.sys.mapper.entpr.EntprEnvrInfoMapper;
import com.guoheng.hazard.sys.model.dto.entpr.EntprEnvrInfoInsertDTO;
import com.guoheng.hazard.sys.model.dto.entpr.EntprEnvrInfoUpdateDTO;
import com.guoheng.hazard.sys.model.entity.entpr.EntprEnvrInfo;
import com.guoheng.hazard.sys.service.entpr.EntprEnvrService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 类功能描述:　EntprEnvrServiceImpl
 *
 * @author fbl
 * @date 2019-11-12 10:12
 */
@Service
public class EntprEnvrServiceImpl implements EntprEnvrService {

    @Resource
    EntprEnvrInfoMapper entprEnvrInfoMapper;

    @Override
    public Result getEntprEnvironments(Long entprId, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<EntprEnvrInfo> entprEnvironments = entprEnvrInfoMapper.getEntprEnvironments(entprId);
        PageInfo<EntprEnvrInfo> entprEnvrInfoPageInfo = new PageInfo<>(entprEnvironments);
        return Result.success(entprEnvrInfoPageInfo);
    }

    @Override
    public Result updateEntprEnvironments(EntprEnvrInfoUpdateDTO entprEnvrInfoUpdateDTO) {
        EntprEnvrInfo entprEnvrInfo = new EntprEnvrInfo();
        BeanUtils.copyProperties(entprEnvrInfoUpdateDTO,entprEnvrInfo);
        entprEnvrInfoMapper.updateEntprEnvironments(entprEnvrInfo);
        return Result.success();
    }

    @Override
    public Result insertEntprEnvironments(EntprEnvrInfoInsertDTO entprEnvrInfoInsertDTO) {
        EntprEnvrInfo entprEnvrInfo = new EntprEnvrInfo();
        BeanUtils.copyProperties(entprEnvrInfoInsertDTO,entprEnvrInfo);
        entprEnvrInfoMapper.insertEntprEnvironments(entprEnvrInfo);
        return Result.success();
    }

    @Override
    public Result deleteEntprEnvironments(Long id) {
        entprEnvrInfoMapper.deleteEntprEnvironments(id);
        return Result.success();
    }

    @Override
    public Result selectEntprEnvironmentById(Long id) {
        EntprEnvrInfo entprEnvrInfo = entprEnvrInfoMapper.selectEntprEnvironmentById(id);
        return Result.success(entprEnvrInfo);
    }
}